package cn.softwin.controller.customer;

import cn.softwin.pojo.CstCustomer;
import cn.softwin.pojo.CstCustomerDetail;
import cn.softwin.service.impl.CustumerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/queryCustomerDetailServlet")
public class QueryCustomerDetailServlet extends HttpServlet {
    private CustumerServiceImpl custumerService = new CustumerServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        Long custId = Long.valueOf(request.getParameter("custId"));
        System.out.println("custId = " + custId);
        CstCustomer cstCustomer = custumerService.queryCustomerById(custId);
        CstCustomerDetail cstCustomerDetail = custumerService.queryCustomerDetailsById(custId);
        request.setAttribute("cst", cstCustomer);
        request.setAttribute("csts", cstCustomerDetail);
        System.out.println("cstCustomer = " + cstCustomer.toString());
        System.out.println("cstCustomerDetail = " + cstCustomerDetail.toString());
        request.getRequestDispatcher("customer/edit.jsp").forward(request, response);
    }
}
